package com.dev.ac.web.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dev.ac.entity.AActive;
import com.dev.ac.service.AActiveService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author 付
 * @Date 2024-04-20 14:48
 * @Version 1.0
 * @description
 * @since 1.0
 */
@Slf4j
public class ActiveExpiredTask extends QuartzJobBean {
	@Autowired
	AActiveService aActiveService;

	@Override
	@Transactional(rollbackFor = Exception.class)
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		log.info("对于活动过期时间处理的定时任务处理器执行了--->{}", context);
		// 查询所有过期的数据
		List<AActive> aActives = aActiveService.list(new QueryWrapper<AActive>()
				.eq("is_delete", 0)
				.eq("status", 1)
				.lt("dead_time", LocalDateTime.now())
		);
		for (AActive aActive : aActives) {
			aActive.setStatus(2);
		}

		aActiveService.updateBatchById(aActives);
	}

	/**
	 * 定时任务执行
	 *
	 * @param context 定时任务上下文
	 * @throws JobExecutionException
	 */

}
